const app = getApp()
const cookieUtil = require("../../utils/manager_cookie.js")
Page({
	data: {
		account: "",
		password: "",
	},
	onLoad() {

	},
	managerLogin() {
		let data = {
			account: this.data.account,
			password: this.data.password,
		}
		const url = app.globalData.baseUrl + app.globalData.clublikestatusUrl

		let promise = new Promise((resolve, reject) => {
			my.request({
				url,
				method: "POST",
				data,
				headers: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				success: (res) => {
					resolve(res)
				}
			})
		})

		promise.then((res) => {
			console.log(res)
			if (res.data.code == "fail") {
				my.showToast({
					type: 'fail',
					content: res.data.message,
					duration: 2000,
				})
			} else {
				//保存cookie
				const cookie = cookieUtil.getSessionIdFromResponse(res)
				cookieUtil.setCookieToStorage(cookie)

				my.showToast({
					type: 'success',
					content: res.data.message,
					duration: 2000,
					success: () => {
						app.globalData.managerStatus = true
						my.switchTab({
							url: '/pages/clubmanager/clubmanager'
						})
					}
				})
			}
		})
	},
	managerAccount(e) {
		this.setData({
			account: e.detail.value
		})
	},
	managerPassword(e) {
		this.setData({
			password: e.detail.value
		})
	}
});
